package com.dunqi.gpm.cangxi.WeekReport.WeekPlan.WeekPlanDetail;

import android.annotation.SuppressLint;

import com.dunqi.gpm.cangxi.WeekReport.Model.Projects;
import com.dunqi.gpm.cangxi.common.api.ApiFactory;
import com.dunqi.gpm.cangxi.common.api.RxSchedulers;
import com.dunqi.gpm.cangxi.common.base.Data;
import com.dunqi.gpm.cangxi.common.util.CommonUtil;
import com.dunqi.gpm.cangxi.home.bean.Page;

import org.jetbrains.annotations.NotNull;

import io.reactivex.functions.Consumer;

public class DataModel {
    public void projectWeeklyPlanSave(DataResult dataResult, String weeks, String projectId, String creatTime, String context, String weeklyPlanId) {
        ApiFactory.getInstance()
                .projectWeeklyPlanSave(CommonUtil.getDeviceId(), weeks, projectId, creatTime, context, weeklyPlanId)
                .compose(RxSchedulers.io_main())
                .subscribe(data -> {
                    dataResult.success2(data);
                }, throwable -> {
                    dataResult.fail(throwable);
                });
    }

    public void delete(int weekPlanId, @NotNull DataResult dataResult) {
        ApiFactory.getInstance()
                .projectWeekPlandelete(CommonUtil.getDeviceId(), weekPlanId)
                .compose(RxSchedulers.io_main())
                .subscribe(data -> {
                    dataResult.delete(data);
                }, throwable -> {
                    dataResult.fail(throwable);
                });

        ApiFactory.getInstance()
                .projectWeekPlandelete(CommonUtil.getDeviceId(), weekPlanId)
                .compose(RxSchedulers.io_main()).subscribe(new Consumer<Data>() {
            @Override
            public void accept(Data data) throws Exception {

            }
        });
    }

    interface DataResult {
        void success(Page<Projects> data);

        void fail(Throwable throwable);

        void success2(Data data);
        void delete(Data data);
    }

    @SuppressLint("CheckResult")
    public void getProjects(DataResult dataResult) {
        ApiFactory.getInstance()
                .projectWeeklyPlanProjectName(CommonUtil.getDeviceId())
                .compose(RxSchedulers.io_main())
                .subscribe(data -> {
                    dataResult.success(data);
                }, throwable -> {
                    dataResult.fail(throwable);
                });
    }
}
